﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Collections;
using System.Reflection;
using UmlControlLibrary.Tools;
using UmlControlLibrary;
using System.Collections.Specialized;

namespace UmlControlLibrary
{
    public class UmlNote : DiagramElement
    {
        public new class Events
        {
            public static Event LinksModified = new Event("Links" + Event.Modified, typeof(UmlElement));
        }

        public ObservableCollection<string> AnnotedElements
        {
            get;
            set;
        }
       
        public UmlNote(string noteName)
            : base(noteName)
        {
            Metadata.Add("AllowUmlTreeviewDnd", false);
            AnnotedElements = new ObservableCollection<string>();
            AnnotedElements.CollectionChanged += new NotifyCollectionChangedEventHandler(AnnotedElements_CollectionChanged);
        }

        void AnnotedElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            EventService.BroadcastEvent(this, Events.LinksModified);
        }
    
        protected override ControlTemplate GetTemplate()
        {
            return DiagramElement.DiagramElementTemplateFactory(typeof(UmlNoteControl));
        }

        public override ObservableCollection<UmlElement> GetChilds()
        {
            ObservableCollection<UmlElement> elements = base.GetChilds();
            return elements;
        }

        public void LinkNote(UmlElement element2)
        {
            if (!AnnotedElements.Contains(element2.Name))
                AnnotedElements.Add(element2.Name);
        }
    }
}
